<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName"  @formSubmit="formSubmit">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
import {errorModal,ignoreHtml,getUrl,confirmModal, ptFloat, minusF } from '@/static/js/common.js';
import {buildFormData,formValidation,getEditorTitle,changeConfigAttr,hasEditor,tranferToEditors, changeEditor,setSubmitSubValue, configSelectData, hasValue,formShowLoading ,getFormFields,formModelLoad,getWorkCacheKey} from '@/static/js/formUtil.js';
import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	
export default{
	provide() {
		return {
			formPage: this
		};
	},
	data() {
		return buildFormData({
			userCache:'obj-w-weekrepotr-user-cache',
			yearWeekData: [],
			salaryPosId:"",
			editEntry:false,
			editId:'',
			canEditorEvaMultiOffId:false
		})
	},
	computed: {
		...mapState(useLoginUserStore, ['userName', 'userId'])
	},
	methods:{
		onSelectPos(item){
			let _that = this
			_that.$refs.autoform.formdata.instName = item.instName
			_that.loadYear(item.id,_that.$refs.autoform.formdata.userId)
		},
		verifyData(){
			let _that = this
			if(_that.subEditorObj["title17"].workList.length >= 15){
				_that.om.toast('会议报告事项清单条数最多只能编辑15条')
				return false
			}else{
				return true
			}
		},
		initSubData() {
			Object.assign(this, {
				workList_title1: [], //上周绩效指标执行情况
				ms_title_title1: '',
				workList_title2: [], //上周重点工作项完成情况
				ms_title_title2: '',
				workList_title3: [], //上周重点工作调整情况
				ms_title_title3: '',
				workList_title5: [], //截止上周未按期完工入库的产品信息
				ms_title_title5: '',
				workList_title6: [], //本周需完工入库的订单信息
				ms_title_title6: '',
				workList_title8: [], //本周绩效指标计划
				ms_title_title8: '',
				workList_title4: [], //本周重点工作项计划
				ms_title_title4: '',
				ms_title_title9: '', //上周计划工作要点
				ms_title_title12: '', //上周指标或工作项未完成说明
				ms_title_title11: '', //上周报告事项
				ms_title_title16: '', //上周项目完成情况报告
				ms_title_title15: '', //上周出差行程
				workList_title10: [], //本周临时工作计划
				ms_title_title10: '',
				ms_title_title13: '',
				ms_title_title14: '',//可阅读人员
				selectUsers:[],
				saveBtnText:""
			})
		},
		getYearWeek(){
			let _that = this
			_that.om.request(
				"tweekMeetingReport/getYearWeek",
					{
						year:_that.$refs.autoform.formdata.year,
						week:_that.$refs.autoform.formdata.week
					}
			).then(res=>{
				let groups = _that.$refs.autoform.configData
				for(let item of groups){
					let title = ""
					if(!item.originalTitle){
						title = item.title
					}else{
						title = item.originalTitle
					}
					if(title !== undefined && title.indexOf("上周") != -1){
						if(!item.originalTitle){
							_that.$refs.autoform.changeConfigAttr(item.key,"originalTitle",item.title)
						}
						for(let editor of item.editors){
							if(editor.isfull || editor.type =="subbox"){
								let newTitle = title.replace(/上周/,_that.$refs.autoform.formdata.year+'第'+_that.$refs.autoform.formdata.week+'周')
								_that.$refs.autoform.changeEditor(item.key,editor.valueField,"title",newTitle)
							}
						}
						if(item.key=="title1"){
								let newTitle = title.replace(/上周/,_that.$refs.autoform.formdata.year+'第'+_that.$refs.autoform.formdata.week+'周'+res.value.d11d22)
								_that.$refs.autoform.changeConfigAttr(item.key,"title",newTitle)
								_that.ms_title_title1 = newTitle
						}else{
							let newTitle = title.replace(/上周/,_that.$refs.autoform.formdata.year+'第'+_that.$refs.autoform.formdata.week+'周')
							_that.$refs.autoform.changeConfigAttr(item.key,"title",newTitle)
							if(item.key=="title6"){
								_that.ms_title_title6 = newTitle
							}
						}
					}else if(title !== undefined && title.indexOf("本周")!= -1){
						if(!item.originalTitle){
							_that.$refs.autoform.changeConfigAttr(item.key,"originalTitle",item.title)
						}
						for(let editor of item.editors){
							if(editor.isfull || editor.type =="subbox"){
								let newTitle = title.replace(/本周/,_that.$refs.autoform.formdata.year+'第'+(Number(_that.$refs.autoform.formdata.week) + 1)+'周')
								_that.$refs.autoform.changeEditor(item.key,editor.valueField,"title",newTitle)
							}
						}
						if(item.key=="title8" || item.key=="title10"){
							let newTitle = title.replace(/本周/,_that.$refs.autoform.formdata.year+'第'+(Number(_that.$refs.autoform.formdata.week) + 1)+'周'+res.value.d33d44)
							_that.$refs.autoform.changeConfigAttr(item.key,"title",newTitle)
							if(item.key=="title8"){
								_that.ms_title_title8 = newTitle
							}else{
								_that.ms_title_title10 = newTitle
							}
						}else{
							let newTitle = title.replace(/本周/,_that.$refs.autoform.formdata.year+'第'+(Number(_that.$refs.autoform.formdata.week) + 1)+'周')
							_that.$refs.autoform.changeConfigAttr(item.key,"title",newTitle)
						}
					}
				}
			})
		},	
		verifyInfo(){
			let formdata = this.$refs.autoform.formdata
				if(!formdata.zposId || !formdata.week || !formdata.year){
					this.om.toast('请先选择制表人岗位，年份和周数',3000)
					return false
				}
		},
		getWorkParam6(){
			let _that = this
			return{
				title:_that.ms_title_title6
			}
		},
		getWorkParam8(){
			let _that = this
			return{
				posId:this.$refs.autoform.formdata.posId,
				year: this.$refs.autoform.formdata.year,
				week:this.$refs.autoform.formdata.week,
				title:_that.ms_title_title8
			}
		},
		getWorkParam10(){
			let _that = this
			let date = ''
			if(_that.$refs.autoform.formdata.weekRange){
				let dateList = _that.$refs.autoform.formdata.weekRange.split('～')
				 date = dateList[1]
			}
			return{
				title:_that.ms_title_title10,
				canEditorEvaMultiOffId:_that.canEditorEvaMultiOffId,
				date:date,
				busCode:_that.busCode
			}
		},
		getWorkParam(){
			let _that = this
			return{
				zposId:this.$refs.autoform.formdata.zposId,
				year: this.$refs.autoform.formdata.year,
				week:this.$refs.autoform.formdata.week,
				title:_that.ms_title_title1
			}
		},
		async getPosComboboxByUser(id){
			let _that = this
			let posList = await _that.om.request(
				"orgInstPosUserOfficial/getPosComboboxByUser",
				{
					userId:id
				}
			)
			_that.$refs.autoform.changeEditor('title0','posId','data',configSelectData(posList,'id','posName'))
			if(!_that.editEntry){
				_that.$refs.autoform.initSelectVal('title0','posId')
			}else{
				_that.$refs.autoform.initSelectIndex('title0','posId')
				_that.editEntry = false
			}
			_that.loadYear(_that.$refs.autoform.formdata.posId,_that.$refs.autoform.formdata.userId);
		},
		formSubmit() {
			let _that = this
			_that.om.formSave('tweekMeetingReport/addTweekMeetingReport', _that.formdata, _that);
		},
		loadYear(posId,userId) {
			let _that = this;
			this.om
				.request('tweekMeetingReport/getYearWeekList', {
					posId: posId,
					userId:userId,
					editId:_that.editId
				})
				.then(res => {
					if (res.succeed) {
						if (res.value && !res.value.tip) {
							if(this.edit){
								_that.$refs.autoform.initSelectIndex("topinfo","year")
								if (res.value.list && res.value.list.length > 0) {
									_that.yearFunc(res.value.list);
								}
							}else{
								if (res.value.list && res.value.list.length > 0) {
									_that.yearFunc(res.value.list);
								}
							}
						}else if(res.value.tip) {
							errorModal(_that, '提示信息', ignoreHtml(res.value.tip), function() {
								_that.clearZpos();
							});
						}
					} else {
						_that.om.toast(res[0].msg);
					}
				});
		},
		yearFunc(datas) {
			var arr = [];
			if (datas.length > 1 && datas[0].year === datas[1].year) {
				arr.push(datas[0]);
			}else{
				arr = datas;
			}
			this.yearWeekData = datas;
			this.$refs.autoform.changeEditor('title0', 'year', 'data', configSelectData(arr, 'year', 'year'));
			this.$refs.autoform.initSelectVal("title0","year")
		},
		clearZpos() {
			this.$refs.autoform.clear('title0', 'posId');
			this.$refs.autoform.clear('title0', 'year');
			this.$refs.autoform.clear('title0', 'week');
			this.$refs.autoform.clear('title0', 'weekRange');
			this.$refs.autoform.clear('title0', 'instName');
			this.initSubData();
		},
		onSelectYear(item) {
			let arr = []
			if(this.yearWeekData.length){
				if(this.yearWeekData.length > 1 && this.yearWeekData[0].year !== this.yearWeekData[1].year){
					for(let index in this.yearWeekData){
						if(item.year === this.yearWeekData[index].year){
							if(Number(index)===1){
								arr.push(this.yearWeekData[index])
							}else{
								arr = this.yearWeekData
							}
						}
					}
				}else{
					arr = this.yearWeekData
				}
			}
			 this.$refs.autoform.clear("title0","week")
			 this.$refs.autoform.clear("title0","weekRange")
			 this.$refs.autoform.changeEditor('title0', 'week', 'data', configSelectData(arr, 'week', 'week'));
			 this.$refs.autoform.initSelectVal("title0","week")
		},
		clearYear(){
			this.$refs.autoform.clear('topinfo', 'year');
			this.$refs.autoform.clear('topinfo', 'week');
			this.$refs.autoform.clear('topinfo', 'weekRange');
			this.initSubData();
		},
		onSelectWeek(item) {
			let _that = this;
			//_that.getYearWeek()
			for(let index in _that.subEditorObj){
				if(index != "title10" && index != "title17"&& index != "title8"){
					_that.subEditorObj[index].workList = [] 
				}
			}
			if(item && item.week){
				_that.om.request(
					'tweekMeetingReport/getDatas',
					{	
						 
						posId: _that.$refs.autoform.formdata.posId,
						userId:_that.$refs.autoform.formdata.userId,
						year: _that.$refs.autoform.formdata.year,
						week: item.week
					},
					'post'
				)
				.then(data => {
					if (data.succeed && data.value) {
						for(var i in data.value){
							//if(data.value[i] instanceof Array && data.value[i].length){
							if(Object.prototype.toString.call(data.value[i])==='[object Array]' && data.value[i].length){
								for(let index in _that.subEditorObj){
									if(!_that.edit){
										if(index == i ){
											_that.subEditorObj[index].workList = data.value[index];
										}
									}
								}
							}else if(typeof(data.value[i]) == "string"){
								if(i == "weekRange"){
									_that.$refs.autoform.formdata.weekRange = data.value[i]
								}else if(i == "lastRemark"){
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,i,data.value[i])
								} 
							}
						}
						if(!_that.$refs.autoform.formdata.lastRemark){
							_that.$refs.autoform.changeConfigAttr("title9","isShow",false)
						}else{
							_that.$refs.autoform.changeConfigAttr("title9","isShow",true)
						}
						if(_that.subEditorObj["title2"] &&!_that.subEditorObj["title2"].workList.length){
							_that.$refs.autoform.changeConfigAttr("title2","isShow",false)
						}else{
							_that.$refs.autoform.changeConfigAttr("title2","isShow",true)
						}
						if(_that.subEditorObj["title3"] &&!_that.subEditorObj["title3"].workList.length){
							_that.$refs.autoform.changeConfigAttr("title3","isShow",false)
						}else{
							_that.$refs.autoform.changeConfigAttr("title3","isShow",true)
						}
						if(_that.subEditorObj["title4"] &&!_that.subEditorObj["title4"].workList.length){
							_that.$refs.autoform.changeConfigAttr("title4","isShow",false)
						}else{
							_that.$refs.autoform.changeConfigAttr("title4","isShow",true)
						}
						if(!_that.edit){
							if(_that.subEditorObj["title5"] && !_that.subEditorObj["title5"].workList.length){
								_that.$refs.autoform.changeConfigAttr("title5","isShow",false)
							}else{
							_that.$refs.autoform.changeConfigAttr("title5","isShow",true)
							}
							if(_that.subEditorObj["title6"] &&!_that.subEditorObj["title6"].workList.length){
								_that.$refs.autoform.changeConfigAttr("title6","isShow",false)
							}else{
							_that.$refs.autoform.changeConfigAttr("title6","isShow",true)
							}
						}
						if(_that.subEditorObj["title1"] &&!_that.subEditorObj["title1"].workList.length){
							_that.$refs.autoform.changeConfigAttr("title1","isShow",false)
						}else{
							_that.$refs.autoform.changeConfigAttr("title1","isShow",true)
						}
						if(_that.subEditorObj["title8"] && data.value["title8"]){
							_that.$refs.autoform.changeConfigAttr("title8","isShow",true)
						}else{
							_that.$refs.autoform.changeConfigAttr("title8","isShow",false)
						}
					}
				});
			}
		},
		onSelectZpos(item) {
			let _that = this;
			this.om
				.request('posBusiAuth/GW165', {
					posId: item.id,
					code: _that.busCode
				})
				.then(res => {
					if (res.succeed) {
						if (res.value.tip) {
							errorModal(_that, '提示信息', res.value.tip, function() {
								_that.clearZpos();
							});
						} else {
						}
					} else {
						_that.om.toast(res[0].msg);
					}
				});
		},
		cloneSubData(fielName,subName,data){
			let _that = this
			let dataList = []
			if(subName === 'index8'){
				if(data.index8 === null){
					 dataList = new Array()
				}else{
					 dataList = _that._.cloneDeep(data.index8)
				}
			}else if(subName === 'index1'){
				if(data.index1 === null){
					 dataList = new Array()
				}else{
					 dataList = _that._.cloneDeep(data.index1)
				}
			}else if(subName === 'work'){
				dataList = _that._.cloneDeep(data.works)
			}else if(subName ==='order'){
				dataList = _that._.cloneDeep(data.orders)
			}else if(subName ==='item'){
				dataList = _that._.cloneDeep(data.items)
			}else{
				 dataList = _that._.cloneDeep(data.datas[subName])
			}
			if(dataList !== undefined){
				_that.subEditorObj[fielName].workList = dataList
			}
			_that.$refs.autoform.$set(_that.$refs.autoform.formdata, subName, JSON.stringify(dataList))
			_that.$set(_that.formdata, subName, JSON.stringify(dataList))
			delete data.dataList
		},
		initLoad(options){
			let _that = this
			let ajaxArr = [{
				url:"wxPosBusiAuth/isnewList",
				param:{
					code:options.code
				},
				method:"post"
			},
				urlUtil.dataDictInitValueUrl('DD021025001') 
			]
			let fileId = options.fileId
			if(fileId){
				_that.editId = fileId
				ajaxArr.push({
					url:"tweekMeetingReport/getInfo",
					param:{
						id:fileId
					},
					method:"post"
				})
			}
			formModelLoad(ajaxArr,function(res,mainData){
				if(res[1].value == 0){
					_that.canEditorEvaMultiOffId = true
				}
				if(_that.subEditorObj["title10"]){
					let att = {
						getWorkParam:"getWorkParam10"
					}
					let configData = _that.subConfigData["title10"]
					if(hasEditor("title10","workName",configData)){
						att.titleTemplate = "<%= workName || '未填写'%>"
					}
					if(hasEditor("title10","maxScore",configData)){
						let title = getEditorTitle("title10","maxScore",configData)
						att.titleTemplate = att.titleTemplate+'('+title+":<%= maxScore || '未填写'%>"+')'
					}
					if(hasEditor("title10","workOutput",configData)){
						let title = getEditorTitle("title10","workOutput",configData)
						att.subtitle1Template = title+":<%= workOutput || '未填写' %>"
					}
					if(hasEditor("title10","deliveryName",configData)){
						let title = getEditorTitle("title10","deliveryName",configData)
						att.subtitle1Template = att.subtitle1Template + ' | '+title+":<%= deliveryName || '未填写' %>"
					}
					if(hasEditor("title10","dutyOffId",configData)){
						let title = getEditorTitle("title10","dutyOffId",configData)
						att.subtitle2Template = title+":<%= dutyOffName|| '未填写' %>"
					}
					if(hasEditor("title10","evaOffId",configData)){
						let title = getEditorTitle("title10","evaOffId",configData)
						att.subtitle2Template = att.subtitle2Template+'  |'+ title+":<%= evaOffName || '未填写' %>"
					}
					if(hasEditor("title10","planEnd",configData)){
						let title = getEditorTitle("title10","planEnd",configData)
						att.subtitle3Template = title+":<%= planEnd || '未填写' %>"
					}
					changeEditor("title10","work",att,mainData)
				}
				if(_that.subEditorObj["title17"]){
					let att = {
					}
					let configData = _that.subConfigData["title17"]
					if(hasEditor("title17","itemName",configData)){
						let title = getEditorTitle("title17","itemName",configData)
						att.titleTemplate = "<%= itemName || '未填写'%>"
					}
					changeEditor("title17","item",att,mainData)
				}
				if(_that.subEditorObj["title8"]){
					let att = {
						getWorkParam:"getWorkParam8"
					}
					let configData = _that.subConfigData["title8"]
					if(hasEditor("title8","indexId",configData)){
						let title = getEditorTitle("title8","indexId",configData)
						att.titleTemplate = title+':<%=indexName || 未填写%>'
					}
					if(hasEditor("title8","targetValueName",configData)){
						let title = getEditorTitle("title8","targetValueName",configData)
						att.subtitle1Template = title+":<%= targetValueName || '未填写'%>"
					}
					if(hasEditor("title8","currentPlanNum",configData)){
						let title = getEditorTitle("title8","currentPlanNum",configData)
						att.subtitle2Template = title+":<%= currentPlanNum || '未填写'%>"
					}
					changeEditor("title8","index8",att,mainData)
				}
				if(_that.subEditorObj["title1"]){
					changeEditor('title1', 'index1', {
						showDel: false,
						showAdd:false,
						getWorkParam:"getWorkParam1",
						titleTemplate:"<%= '指标名称:' + indexName + '('+ orderNum + ')' %>",
						subtitle1Template:"<%= '年度目标值:'+ targetValueName %>",
						subtitle2Template:"<%= '周计划数:'+ (currentPlanNum ||'未填写')  %>"
					}, null, mainData)
				}
				if(_that.subEditorObj["title5"]){
					changeEditor('title5', 'product', {
						showDel: false,
						showAdd:false,
						titleTemplate:"<%= '型号规格:' + std %>",
						subtitle1Template:"<%= '单位:'+ unit +'数量'+ storageSum %>",
						subtitle2Template:"<%= '产品来源:'+ sourceName %>",
						subtitle3Template:"<%= '发货日期:'+ date +'实际入库时间:' + storageDate  %>"
					}, null, mainData)
				}
				if(_that.subEditorObj["title2"]){
					let att = {
						showArrow:false,
						showDel: false,
						showAdd:false,
						}
					let configData = _that.subConfigData["title2"]
					if(hasEditor("title2",'itemName',configData)){
						att.titleTemplate = "<%= itemName || '未填写'%>"
					}
					if(hasEditor("title2",'orderNum',configData)){
						let title = getEditorTitle("title2","orderNum",configData)
						att.subtitle1Template = title + ":<%= orderNum || '未填写'%>"
					}
					if(hasEditor("title2",'deliveryName',configData)){
						let title = getEditorTitle("title2","deliveryName",configData)
						if(att.subtitle1Template){
							att.subtitle1Template = att.subtitle1Template +' | '+ title + ":<%= deliveryName || '未填写' %>"
						}else{
							att.subtitle1Template = title + ":<%= deliveryName || '未填写'%>"
						}
					}
					if(hasEditor("title2",'planEndDate',configData)){
						let title = getEditorTitle("title2","planEndDate",configData)
						att.subtitle2Template = title + ":<%= planEndDate || '未填写'%>"
					}
					if(hasEditor("title2",'actualEndDate',configData)){
						let title = getEditorTitle("title2","actualEndDate",configData)
						if(att.subtitle2Template){
							att.subtitle2Template = att.subtitle2Template+' | '+title + ":<%= actualEndDate || '未填写'%>"
						}else{
							att.subtitle2Template = title + ":<%= actualEndDate || '未填写'%>"
						}
					}
					if(hasEditor("title2",'evaluateUserName',configData)){
						let title = getEditorTitle("title2","evaluateUserName",configData)
						att.subtitle2Template = att.subtitle2Template+' | '+title + ":<%= evaluateUserName || '未填写'%>"
					}
					if(hasEditor("title2",'maxScore',configData)){
						let title = getEditorTitle("title2","maxScore",configData)
						att.subtitle3Template = title + ":<%= maxScore || '未填写'%>"
					}
					if(hasEditor("title2",'score',configData)){
						let title = getEditorTitle("title2","score",configData)
						att.subtitle3Template = att.subtitle3Template+ ' | '+title + ":<%= score || '未填写'%>"
					}
					if(hasEditor("title2",'remark',configData)){
						let title = getEditorTitle("title2","remark",configData)
						att.subtitle3Template = att.subtitle3Template+' | '+title + ":<%= remark || '未填写'%>"
					}
					changeEditor("title2","title2",att,mainData)
					// changeEditor('title2', 'title2', {
					// 	showArrow:false,
					// 	showDel: false,
					// 	showAdd:false,
					// 	titleTemplate:"<%= '工作项名称:' + itemName %>",
					// 	subtitle1Template:"<%= '交付物:'+ deliveryName %>",
					// 	subtitle2Template:"<%= '年度项:'+ (keyItem || '未填写') %>",
					// 	subtitle3Template:"<%= '计划完成日期:'+ planEndDate +'实际完成日期:' + (actualEndDate || '未填写')  %>"
					// }, null, mainData)
				}
				if(_that.subEditorObj["title3"]){
					let att = {
						showAdd:false,
						showDel:false,
						showArrow:false
					}
					let configData = _that.subConfigData["title3"]
					if(hasEditor("title3","workName",configData)){
						att.titleTemplate = "<%= workName || '未填写'%>"
					}
					if(hasEditor("title3","deliveryName",configData)){
						let title = getEditorTitle("title3","deliveryName",configData)
						att.subtitle1Template = title + ":<%= deliveryName || '未填写'%>"
					}
					if(hasEditor("title3","origPlanEnd",configData)){
						let title = getEditorTitle("title3","origPlanEnd",configData)
						att.subtitle2Template = title+":<%= origPlanEnd || '未填写'%>"
					}
					if(hasEditor("title3","adjustTypeName",configData)){
						let title = getEditorTitle("title3","adjustTypeName",configData)
						att.subtitle3Template = title+":<%= origPlanEnd || '未填写'%>"
					}
					if(hasEditor("title3","adjustPlanEnd",configData)){
						let title  = getEditorTitle("title3","adjustPlanEnd",configData)
						if(att.subtitle3Template){
							att.subtitle3Template = att.subtitle3Template + "|" +title+"<%= adjustPlanEnd || '未填写'%>"
						}else{
							att.subtitle3Template = title+"<%= adjustPlanEnd || '未填写'%>"
						}
					}
					changeEditor("title3","title3",att,mainData)
					// changeEditor('title3', 'title3', {
					// 	showDel: false,
					// 	showAdd:false,
					// 	titleTemplate:"<%= '工作项名称:' + workName %>",
					// 	subtitle1Template:"<%= '交付物:'+ deliveryName %>",
					// 	subtitle2Template:"<%= '原计划完成日期:'+ (origPlanEnd || '未填写') %>",
					// 	subtitle3Template:"<%= '调整类别:'+ adjustTypeName +',拟调整完成日期:' + (adjustPlanEnd || '未填写')  %>"
					// }, null, mainData)
				}
				if(_that.subEditorObj["title4"]){
					let att = {}
					let configData = _that.subConfigData["title4"]
					if(hasEditor("title4","workName3",configData)){
						att.titleTemplate = "<%= workName3 || '未填写'%>"
					}
					if(hasEditor("title4","deliveryName3",configData)){
						let title = getEditorTitle("title4","deliveryName3",configData)
						att.subtitle1Template = title + ":<%= deliveryName3 || '未填写'%>"
					}
					if(hasEditor("title4","planEnd3",configData)){
						let title = getEditorTitle("title4","planEnd3",configData)
						att.subtitle2Template = title + ":<%= planEnd3 || '未填写'%>"
					}
					if(hasEditor("title4","workOutput3",configData)){
						let title = getEditorTitle("title4","workOutput3",configData)
						att.subtitle3Template = title + "<%= workOutput3 ||'未填写'%>"
					}
					changeEditor("title4","title4",att,configData)
					// changeEditor('title4', 'title4', {
					// 	showDel: false,
					// 	showAdd:false,
					// 	titleTemplate:"<%= '工作项名称:' + workName3 %>",
					// 	subtitle1Template:"<%= '交付物:'+ deliveryName3 %>",
					// 	subtitle2Template:"<%= '原计划完成日期:'+ (planEnd3 || '未填写') %>",
					// 	subtitle3Template:"<%= '拟完成数量、状态、效果' +  workOutput3 %>"
					// }, null, mainData)
				}
				if(_that.subEditorObj["title6"]){
					changeEditor('title6', 'order', {
						showAdd:false,
						showDel:false,
						getWorkParam:"getWorkParam6",
						titleTemplate:"<%= '单据编码:' + tableCode %>",
						subtitle1Template:"<%= '业务负责机构:'+ instName   %>",
						subtitle2Template:"<%=  '业务负责人'+ userName +'|'+ '顾客代码:'+ customerCode %>",
						subtitle3Template:"<%= '制单人:'+ tableUserName +'制单日期:' + tableDate  %>"
					}, null, mainData)
				}
					changeEditor("topinfo","zposId","data",configSelectData(res[0],"id","posName"),mainData)					
					changeEditor("title0","userId",{
						"link":'../../public/searchUser/searchUser',
						"linkParam": {
							cachename: _that.userCache,
							isNew:true,
							isSingle:true
						}
					},null,mainData)
					changeConfigAttr("title17","subTitle",'事项清单条数最多15条',mainData)
					if(fileId){
						let fielArr = getFormFields(mainData)
						fielArr.push("id")
						for(let index in res[2].value.tweekMeetingReport){
							if(fielArr.includes(index)){
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,index,res[2].value.tweekMeetingReport[index])
								_that.$set(_that.formdata,index,res[2].value.tweekMeetingReport[index])
							}
						}
						for(var i=0; i<=17;i++){
							if(i==1){
								if(hasEditor("title1","index1",mainData)){
									_that.cloneSubData("title"+[i],'index1',res[2].value)
								}
							}else if(i==8){
								if(hasEditor("title8","index8",mainData)){
									_that.cloneSubData("title"+[i],'index8',res[2].value)
								}
							}else if(i == 10){
								if(hasEditor("title10","work",mainData)){
									_that.cloneSubData("title"+[i],'work',res[2].value)	
								}
							}else if(i ==6){
								if(hasEditor("title6","order",mainData)){
									_that.cloneSubData("title"+[i],'order',res[2].value)	
								}
							}else if(i ==17){
								if(hasEditor("title17","item",mainData)){
									_that.cloneSubData("title"+[i],'item',res[2].value)	
								}
							}else{
								if(hasEditor("title"+[i],"title"+[i],mainData)){
									_that.cloneSubData("title"+[i],"title"+[i],res[2].value)	
								}
							}
						}
					}
					_that.$nextTick(async function(){
						if(!_that.edit){
							_that.$refs.autoform.initSelectVal("topinfo","zposId")
						}else{
							_that.$refs.autoform.initSelectIndex("topinfo","zposId")
							_that.onSelectWeek({week:_that.$refs.autoform.formdata.week})
						}
						if(!_that.edit){
							_that.$refs.autoform.formdata.userId = _that.userId
							_that.$refs.autoform.formdata.userName = _that.userName
							await _that.getPosComboboxByUser(_that.userId,_that.$refs.autoform.formdata.posId)
						}else{
							_that.editEntry = true
							await _that.getPosComboboxByUser(_that.$refs.autoform.formdata.userId,_that.$refs.autoform.formdata.posId)
						}
					})
			},options)
		}
	},
	onLoad(options) {
		this.initLoad(options)
	},
	onUnload(){
		//#ifdef APP-PLUS
		let _that = this;
		if (_that.$refs.autoform) {
			for (var fieldId in _that.subEditorObj) {
				uni.removeStorage({
					key: getWorkCacheKey(fieldId)
				});
			}
		}
		//#endif
	},
	onShow() {
		let _that = this
		if (_that.$refs.autoform) {
			for (var fieldId in _that.subEditorObj) {
				let editor = _that.subEditorObj[fieldId];
				uni.getStorage({
					key: getWorkCacheKey(fieldId),
					success: function(res) {
						editor.workList = res.data;
						uni.removeStorage({
							key: getWorkCacheKey(fieldId)
						});
					}
				});
				uni.getStorage({
					key:_that.userCache,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.userId = d.id
							formdata.userName = d.username
							_that.getPosComboboxByUser(d.id)
							uni.removeStorage({
								key:_that.userCache
							})
						}
					}
				})
			}
		}
	}
}	
	
	
</script>

<style>
</style>
